﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.BasicsDatum;
using SmartWMS.Server.BasicsDatumServer.CustomerManagementService;
using SmartWMS.Server.BasicsDatumServer.CustomerManagementService.Dto;

namespace SmartWMS.API.Controllers.BasicsDatumMange
{
	/// <summary>
	/// 客户管理控制器
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	[ApiExplorerSettings(GroupName = "BasicsDatum")]
	public class CustomerManagementController : ControllerBase
	{
		private readonly ICustomerManagementService _customerManagementService;

		public CustomerManagementController(ICustomerManagementService customerManagementService)
		{
			_customerManagementService = customerManagementService;
		}

		/// <summary>
		/// 显示客户管理信息
		/// </summary>
		/// <param name="dto">要查询的客户对象 + 分页对象</param>
		/// <returns>返回分页对象</returns>
		[HttpPost]
		public IActionResult GetCustomerManagemenDtoAsync(SearchCustomDto dto)
		{
			try
			{
				var pageObj = _customerManagementService.GetCustomerManagemenDtoAsync(dto);
				return Ok(new
				{
					pageObj.Result.totalCount,
					pageObj.Result.pageCount,
					data = pageObj.Result.data
				});
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 删除客户管理
		/// </summary>
		/// <param name="info">要删除的客户实体</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> DelCustomerManagement(CustomDto info)
		{
			try
			{
				var result = await _customerManagementService.DelCustomerManagement(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 批量删除客户管理
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		public Task<Response<bool>> BatchDelCustomerManagement(CustomDto dto)
		{
			try
			{
				var result = _customerManagementService.BatchDelCustomerManagement(dto);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 添加客户管理（客户联系人）
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> AddCustomDtoAsync(CustomDto info)
		{
			try
			{
				var result = await _customerManagementService.AddCustomDtoAsync(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 反填客户联系人信息
		/// </summary>
		/// <param name="info">要反填的客户联系人信息实体</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<List<CustomContactDto>>> FillCustomContactDtoAsync(CustomContactDto info)
		{
			try
			{
				var result = await _customerManagementService.FillCustomContactDtoAsync(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 反填客户信息
		/// </summary>
		/// <param name="info">要反填的客户信息</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<CustomInputDto>> GetCustomDtoAsync(CustomInputDto info)
		{
			try
			{
				var result = await _customerManagementService.GetCustomDtoAsync(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 修改客户信息
		/// </summary>
		/// <param name="info">要修改的客户信息</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> UpdCustomDtoAsync(CustomDto info)
		{
			try
			{
				var result = await _customerManagementService.UpdCustomDtoAsync(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}
	}
}
